/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TextMessageBox.java
 *
 * Created on Jun 16, 2009, 7:21:36 AM
 */

package org.grid.gui;

/**
 *
 * @author wellington
 */
public class TextMessageBox extends javax.swing.JDialog {

    private TextMessageBox(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    public static void showError(java.awt.Frame parent, Object message, Object trace){
        TextMessageBox tmb = new TextMessageBox(parent, true);
        tmb.setTitle(message.toString());
        tmb.lblMainMessage.setText(message.toString());
        tmb.txtMessage.setText(trace.toString());
        tmb.setVisible(true);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        lblIcon = new javax.swing.JLabel();
        pnlBody = new javax.swing.JPanel();
        pnlButtons = new javax.swing.JPanel();
        btnOK = new javax.swing.JButton();
        pnlMessage = new javax.swing.JScrollPane();
        txtMessage = new javax.swing.JTextArea();
        lblMainMessage = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("");
        setModal(true);
        getContentPane().setLayout(new java.awt.GridBagLayout());

        lblIcon.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/grid/resources/error.png"))); // NOI18N
        lblIcon.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        getContentPane().add(lblIcon, gridBagConstraints);

        pnlBody.setLayout(new java.awt.GridBagLayout());

        pnlButtons.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        btnOK.setText("OK");
        btnOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOKActionPerformed(evt);
            }
        });
        pnlButtons.add(btnOK);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        pnlBody.add(pnlButtons, gridBagConstraints);

        txtMessage.setColumns(20);
        txtMessage.setEditable(false);
        txtMessage.setRows(5);
        pnlMessage.setViewportView(txtMessage);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        pnlBody.add(pnlMessage, gridBagConstraints);

        lblMainMessage.setText("Error message");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        pnlBody.add(lblMainMessage, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(pnlBody, gridBagConstraints);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
    }// </editor-fold>//GEN-END:initComponents

    private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed
        dispose();
    }//GEN-LAST:event_btnOKActionPerformed
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnOK;
    private javax.swing.JLabel lblIcon;
    private javax.swing.JLabel lblMainMessage;
    private javax.swing.JPanel pnlBody;
    private javax.swing.JPanel pnlButtons;
    private javax.swing.JScrollPane pnlMessage;
    private javax.swing.JTextArea txtMessage;
    // End of variables declaration//GEN-END:variables

}
